<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
    <title>智慧社区-物业管理</title>

    <meta name="description" content="Dashboard" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/assets/img/favicon.png" type="image/x-icon">

    <!--Basic Styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/font-awesome.min.css" rel="stylesheet" />

    <!--Beyond styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/beyond.min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/animate.min.css" rel="stylesheet" />
	<script src="${pageContext.request.contextPath}/resource/assets/js/skins.min.js"></script>
</head>
<body>
<!--test-->
<%@include file="../../header.jsp" %>
	<!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">
            <!-- Page Sidebar -->
            <%@include file="../nav.jsp" %><!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb" style="margin-top: 8px;">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">首页</a>
                        </li>
                        <li><a href="#">小区管理</a></li>
                        <li class="active">添加小区</li>
                    </ul>
                </div><!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header position-relative">
                    <div class="header-title" style="margin-top: 2px;">
                        <h1>
                            添加小区
                        </h1>
                    </div><!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div><!--Header Buttons End-->
                </div><!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                	<div class="row">
	                	<div class="col-lg-6 col-sm-6 col-xs-12">
	                		<div class="widget">
                                        <div class="widget-header bordered-bottom bordered-palegreen">
                                            <span class="widget-caption">添加小区</span>
                                        </div>
                                        <div class="widget-body">
                                           <div id="registration-form">
                                                        <form role="form">
                                                            <div class="form-title">
                                                            	小区信息
                                                            </div>
                                                            <div class="row form-group" style="margin-left: 0px !important;">
                                                                 <select id="s1" style="width:30%; margin-right: 32px;">
                                                                 		<option></option>
                                            					</select>
                                            					<select id="s2" style="width:30%;margin-right: 32px;">
                                                                 		<option></option>
                                            					</select>
                                            					<select id="s3" style="width:30%;">
                                                                 		<option></option>
                                            					</select>
                                                            </div>
                                                            
                                                            
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="name" type="text" class="form-control"  placeholder="小区名称" value="${village.name }">
                                                                    <i class="glyphicon glyphicon-align-right"></i>
                                                                </span>
                                                            </div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="address" type="text" class="form-control" placeholder="详细地址" value="${village.address }">
                                                                    <i class="glyphicon glyphicon-map-marker"></i>
                                                                </span>
                                                            </div>
                                                          <div class="form-group">
									                                            <div class="controls">
									                                                <div class="input-group">
									                                                    <input type="text" class="form-control" id="reservation" placeholder="服务有效期" />
									                                                    <span class="input-group-addon">
									                                                        <i class="fa fa-calendar"></i>
									                                                    </span>
									                                                </div>
									                                            </div>
                                                            </div>
                                                            
                                                            <div class="form-title">
                                                                物业费相关设置(以下内容决定通知业主用户缴纳物业费的时间)
                                                            </div>
                                                            
                                                             <div class="form-group">
	                                                             <span class="input-icon icon-right">
		                                                                    <input id="period" type="text" class="form-control"  placeholder="缴费周期（单位：个月），请填写整数" value="${village.period}">
		                                                                    <i class="glyphicon glyphicon-user circular"></i>
		                                                                </span>
                                                                
                                                            </div>
                                                            
                                                            <hr class="wide" />
                                                            <div class="row" style="text-align: right;margin-right: 10px;">
                                                            	<button type="button" class="btn btn-warning" onclick="cancel()"> 取 消 </button>
                                                            	<button type="button" class="btn btn-blue" onclick="save()"> 添 加 </button>
                                                            </div>
                                                            
                                                        </form>
                                                    </div> 
                                        </div>
                                    </div>
	                	</div>
                	
                    </div>
                </div><!-- /Page Body -->
             </div><!-- /Page Content -->
     	</div><!-- /Page Container -->
     </div><!-- /Main Container -->
     	<script src="${pageContext.request.contextPath}/resource/assets/js/jquery-2.0.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath}/resource/assets/js/select2/select2.js"></script>
    <!--Beyond Scripts-->
    <script src="${pageContext.request.contextPath}/resource/assets/js/beyond.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/datetime/bootstrap-datepicker.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/datetime/moment.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/datetime/daterangepicker.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/assets/js/geo.js"></script>
    <script type="text/javascript">
    	$('.loading-container').hide();
    	$('#menu_village').addClass("active open");
    	$('#menu_village_add').addClass("active");
    	var start = "${village.startAt}";
        var end = "${village.endAt}";
        var objectId = "${village.objectId}";
        
        setup();
        if (objectId != "") {
			var startDate = unixToDate(start);
			var endDate = unixToDate(end);
			var date = startDate +" - "+ endDate;
			$('#reservation').val(date);
			preselect('${village.province}');
			$('#s2').val("${village.city}");
			change(2);
			$('#s3').val("${village.district}");
		} else {
			preselect('北京市');
		}
    	$("#s1").select2();
    	$("#s2").select2();
    	$("#s3").select2();
    	
    	$('#reservation').daterangepicker({
			}, function(startDate, endDate) {
				start = startDate+"";
				end = endDate+"";
			}
		);
    	
    	
    	function promptinfo()
        {
        	
        } 
    	
    	function save(){
    		var province = $('#s1').val();
        	var city = $('#s2').val();
        	var district = $('#s3').val();
    		var name = $('#name').val();
    		var address = $('#address').val();
    		var period = $("#period").val();
    		
    		if ($.trim(period) == "") {
				alert("请填写缴费周期！");
				return;
			}else{
				var re =/^[1-9]\d*$/;
				if (!re.test(period)) {
					alert("缴费周期格式不正确，请填写正整数！");
					return;
				}
			}
    		
    		if(city == "地级市"){
    			alert("请选择城市");
    			return;
    		}
    		
    		if(district == "市、县级市、县"){
    			alert("请选择区县");
    			return;
    		}
    		
    		if ($.trim(name) == "" || $.trim(address) == "") {
    			alert("请输入小区名称和详细地址");
    			return;
    		}
    		
    		if(start == "" || end == ""){
    			alert("请选择服务有效期");
    			return;
    		}
    		
    		$('.loading-container').show();
    		$.ajax({
    			"url":"${pageContext.request.contextPath}/village_save",
    			"data":{objectId:objectId,province:province,city:city,name:name,district:district,address:address,startAt:start,endAt:end,period:period},
    			"type":'post',
    			"dataType":'json',
    			"success" : function(result) {
    				$('.loading-container').hide();
    				
    				if (result == 201){
    					alert("鉴权已过期，请重新登录");
    					location.href="/WisdomHome";
    					return;
    				}
    				
    				if (result == 200) {
    					alert("小区保存成功");
    					cancel();
    				}else {
    					alert("提交失败，请检查网络后重试~");
    				}
    			},
    			"error" : function(msg) {
    				alert("error msg:"+msg.responseText);
    			}
    		});
    	}
    	
    	function cancel(){
    		$('#name').val("");
			$('#id').val("");
			$('#username').val("");
			$('#password').val("");
			$('#repassword').val("");
    	}
    	
    </script>
</body>
</html>